#include "threadPool.hpp"
#include <iostream>
#include "task.hpp"

static char op[4] = {'+','-','*','/'};

int calculate(int x,int y,char op)
{
    switch(op)
    {
        case '+' : return x + y;
        break;
        case '-' : return x - y;
        break;
        case '*' : return x * y;
        break;
        case '/' : return x / y;
        break;
    }
}

int main()
{
    srand(time(nullptr));
    //ThreadPool<Task>* tp = new ThreadPool<Task>();      
    ThreadPool<Task>* tp = ThreadPool<Task>::getThreadPool(5);
    tp->run();

    while(true)
    {
         //生产的过程，制作任务的时候，要花时间
        int x = rand() % 100;
        int y = rand() % 100 + 1;
        int index = rand() % 4;
        Task task(x,y,op[index],calculate);

        //std::cout << "制作任务完成: " << x << op[index] << y << "=?" << std::endl;
        logMessage(DEBUG,"制作任务完成: %d%c%d=?",x,op[index],y);

        tp->pushTask(task);
        sleep(1);
    }

    return 0;
}